package com.tjec.project.businessWorkbench.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.framework.security.service.TokenService;
import com.tjec.project.businessWorkbench.domain.BmsBusiness;
import com.tjec.project.businessWorkbench.service.IBmsBusinessService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.ServletUtils;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 业务一览Controller
 * 
 * @author pangyongfeng
 * @date 2020-04-20
 */
@Api(value = "业务一览", tags = {"业务一览接口"})
@RestController
@RequestMapping("/businessWorkbench/businessView")
public class BmsBusinessController extends BaseController
{
    @Autowired
    private IBmsBusinessService bmsBusinessService;
    
    @Autowired
    private TokenService tokenService;

    /**
     * 查询业务一览列表
     */
    @ApiOperation("业务一览列表分页")
    @PreAuthorize("@ss.hasPermi('businessWorkbench:businessView:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmsBusiness bmsBusiness)
    {
        startPage();
        List<BmsBusiness> list = bmsBusinessService.selectBmsBusinessList(bmsBusiness);
        return getDataTable(list);
    }

    /**
     * 导出业务一览列表
     */
    @PreAuthorize("@ss.hasPermi('businessWorkbench:businessView:export')")
    @Log(title = "业务一览", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsBusiness bmsBusiness)
    {
        List<BmsBusiness> list = bmsBusinessService.selectBmsBusinessList(bmsBusiness);
        ExcelUtil<BmsBusiness> util = new ExcelUtil<BmsBusiness>(BmsBusiness.class);
        return util.exportExcel(list, "businessView");
    }

    /**
     * 获取业务一览详细信息
     */
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(bmsBusinessService.selectBmsBusinessByGuid(guid));
    }

    /**
     * 新增业务一览
     */
    @Log(title = "业务一览", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsBusiness bmsBusiness)
    {
        return toAjax(bmsBusinessService.insertBmsBusiness(bmsBusiness));
    }

    /**
     * 修改业务一览
     */
    @ApiOperation("业务一览修改")
    @Log(title = "业务一览", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsBusiness bmsBusiness)
    {
    	bmsBusiness.setUpdateBy(tokenService.getLoginUser(ServletUtils.getRequest()).getUser().getUserId());
        return toAjax(bmsBusinessService.updateBmsBusiness(bmsBusiness));
    }

    /**
     * 删除业务一览
     */
    @PreAuthorize("@ss.hasPermi('businessWorkbench:businessView:remove')")
    @Log(title = "业务一览", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(bmsBusinessService.deleteBmsBusinessByGuids(guids));
    }
}
